package com.wingscode.modules.common.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wingscode.common.utils.PageUtils;
import com.wingscode.common.utils.Query;
import com.wingscode.modules.common.dao.AgentDao;
import com.wingscode.modules.common.entity.AgentEntity;
import com.wingscode.modules.common.entity.UserEntity;
import com.wingscode.modules.common.service.AgentService;
import org.springframework.stereotype.Service;

import java.util.Map;


@Service("agentService")
public class AgentServiceImpl extends ServiceImpl<AgentDao, AgentEntity> implements AgentService {

    @Override
    public PageUtils getList(Map<String, Object> params) {
        Integer type = null, level = null, isStart = null;
        String company = "", startTime = "", endTime = "";

        if (params.containsKey("type") && params.get("type") != null && !params.get("type").toString().isEmpty())
            type = Integer.parseInt(params.get("type").toString());
        if (params.containsKey("level") && params.get("level") != null && !params.get("level").toString().isEmpty())
            level = Integer.parseInt(params.get("level").toString());
        if (params.containsKey("isStart") && params.get("isStart") != null && !params.get("isStart").toString().isEmpty())
            isStart = Integer.parseInt(params.get("isStart").toString());
        if (params.containsKey("company"))
            company = (String) params.get("company");
        if (params.containsKey("startTime"))
            startTime = (String) params.get("startTime");
        if (params.containsKey("endTime"))
            endTime = (String) params.get("endTime");

        IPage<AgentEntity> page = this.baseMapper.getList(new Query<AgentEntity>().getPage(params), company, startTime, endTime,
                type, level, isStart);

        return new PageUtils(page);
    }
}
